package org.genuflex.vo
{
	import mx.collections.ArrayCollection;
	import org.genuflex.utils.GenuflexDataFunctions;
	import org.genuflex.utils.GenuflexDataCache;
	
	/*
	 * GenuflexMetadata is a base class for all VO meta data classes
	 *  MetaData classes will contain information on how the VO relates
	 *  to other VO's in the system
	 */
	public class GenuflexMetadata
	{	
		public var dataCache : GenuflexDataCache = GenuflexDataCache.getInstance();
		
		public var associations : ArrayCollection = new ArrayCollection();
		
		public function addBelongsToAssociation(sourceClass : Class, foreignKeyName : String, name : String, destClass : Class) : void {
			var belongsTo : BelongsToAssociation = new BelongsToAssociation(sourceClass, destClass, foreignKeyName, name);

			dataCache.addAssociation(belongsTo);
			associations.addItem(belongsTo);
		}

		public function addHasManyAssociation(sourceClass : Class, name : String, destClass : Class, foreignKeyName  : String) : void {
			var hasMany : HasManyAssociation = new HasManyAssociation(sourceClass, destClass, foreignKeyName, name);

			dataCache.addAssociation(hasMany);
			associations.addItem(hasMany);
		}

		public function addHasAndBelongsToManyAssociation(sourceClass : Class, name : String, destClass : Class, foreignKeyName  : String) : void {
			var hasAndBelongsToMany : HasAndBelongsToManyAssociation = new HasAndBelongsToManyAssociation(sourceClass, destClass, foreignKeyName, name);

			dataCache.addAssociation(hasAndBelongsToMany);
			associations.addItem(hasAndBelongsToMany);
		}
	}
}